﻿// 7. Write a method that reverses the digits of given decimal number. Example: 256 -> 652

using System;

class ConvertDecimalNumber
{
    static void Main()
    {
        Console.Write("Enter you number : ");
        int number = int.Parse(Console.ReadLine());
        string result = "";
        int reversedNumber = 0;

        if (number >= -9 && number <= 9)
        {
            Console.WriteLine("The number has only one digit so it cannot be reversed.");
            return;
        }
        else if (number <= - 10)
        {
            result = ReverseDecimalNumber(Math.Abs(number));
            int resultReversed = Convert.ToInt32(result);
            reversedNumber = -resultReversed;
        }
        else
        {
            result = ReverseDecimalNumber(number);
            reversedNumber = Convert.ToInt32(result);
        }

        Console.WriteLine("When reverse {0}, the result is {1}.", number, reversedNumber);
    }

    static string ReverseDecimalNumber(int number)
    {
        string stringResult = "";

        while(number > 0)
        {
        int remainder = number % 10;
        number /= 10;
        stringResult += remainder;
        }

        return stringResult;
    }
}
